
const app = getApp()
import { getStorage,setStorage } from "../../utils/localStorage"
import { townName_obtain } from "../../api/homePage"
Component({
    properties: {
    },
    data: {
        navData: {
            level: 4,
            title1: '关注',
            title2: '发现',
        },
        navIndex: 2,
        user: {}, //用户信息
        townName: "", //乡镇名
        pageTop: app.globalData.navHeight + app.globalData.navTop,
        footerIndex: 1,
    },
    lifetimes: {
        attached() {
            this.setValue();
            this.getTownName();
        },
        detached() { },
    },
    pageLifetimes: {
        show() {
            this.getTownName();
        },
    },
    methods: {
        //初始化页面值
        setValue() {
            this.setData({
                user: getStorage("user")
            });
        },
        //获取乡镇名
        getTownName() {
            if (app.globalData.townName === null) {
                townName_obtain({ userId: this.data.user.id }).then(res => {
                    app.globalData.townName = res.data.data.townShipName;
                    this.setData({
                        townName: app.globalData.townName,
                    });
                });
            } else {
                this.setData({
                    townName: app.globalData.townName,
                });
            }
        },
        navMy(e) {
            let index = e.detail;
            this.setData({
                navIndex: index,
            });
        },
        //底部切换栏事件
        footerNav(e) {
            let index = e.detail;
            this.setData({
                footerIndex: index,
            });
            setStorage('pageIndex', this.data.footerIndex);
        },
    },
})